package cn.org.timespace.easyframe.util.sms.telecom.smsUtil;

import java.io.IOException;

import cn.org.timespace.easyframe.util.sms.telecom.smgp.Client;
import cn.org.timespace.easyframe.util.sms.telecom.smgp.bean.Result;
import cn.org.timespace.easyframe.util.sms.telecom.smgp.bean.Submit;
import cn.org.timespace.easyframe.util.sms.telecom.smgp.bean.SubmitBatch;

/**
 * ����Ϣ ����
 * */
public class SMGPSubmitMessage  {
	/**
	 * ����  Ⱥ������Ϣ
	 * @param String[] destnum notNull  Ŀ�����   ���Ŀ�����
	 * @param String content Null     ��������
	 * */
	public static Result Send(String[] destnum,String content) throws IOException{
		//��ȡ�����ļ�����
		Config config = new Config();
		
		//��ȡ���ò���
		String host = config.get("smgwip");
		String account = config.get("smgwaccount");
		String passwd = config.get("smgwpasswd");
		String spid = config.get("smgwspid");
		String spnum = config.get("smgpspnum");
		int port = Integer.parseInt(config.get("smgwport"));
		
		String productid=config.get("productid");
		
		//��ʼ��client
		Client client = new Client(host, port, 2,account, passwd,spid, 0);
		Result result1 = client.Login();
		if(result1.ErrorCode!=0)
			System.out.println("��������l��ʧ�ܣ�");
		else
			System.out.println("��������l�ӳɹ���");
		//����submit
		SubmitBatch submit =new SubmitBatch();
		submit.setSrcTermid(spnum);
		submit.setDestTermid(destnum);
		submit.setMsgContent(content.getBytes("iso-10646-ucs-2"));
		submit.setMsgFormat(8);
		if (productid!=null) submit.setProductID(productid);
		
		// ���Ͷ���
		Result result = client.SendBatch(submit);
		//�˳�
		client.Close();
		return result;
	}
	
	/**
	 * ���Ͷ���Ϣ
	 * @param String destnum notNull  Ŀ����� 
	 * @param String content Null     ��������
	 * */
	public static Result Send(String destnum,String content) throws IOException{
		//��ȡ�����ļ�����
		Config config = new Config();
		
		//��ȡ���ò���
		String host = config.get("smgwip");
		String account = config.get("smgwaccount");
		String passwd = config.get("smgwpasswd");
		String spid = config.get("smgwspid");
		String spnum = config.get("smgpspnum");
		int port = Integer.parseInt(config.get("smgwport"));
		
		String productid=config.get("productid");
		
		//��ʼ��client
		Client client = new Client(host, port, 2,account, passwd,spid, 0);
		
		//����submit
		Submit submit =new Submit();
		submit.setSrcTermid(spnum);
		submit.setDestTermid(destnum);
		submit.setMsgContent(content.getBytes("iso-10646-ucs-2"));
		submit.setMsgFormat(8);
		if (productid!=null) submit.setProductID(productid);
		
		// ���Ͷ���
		Result result = client.Send(submit);
		//�˳�
		client.Close();
		return result;
	}
	
	/**
	 * ���Ͷ���Ϣ
	 * @param String destnum notNull  Ŀ����� 
	 * @param String content Null     ��������
	 * */
	/*
	public static Result Send(int msgtype, int needreport, int priority, String serviceid,
			String feetype, String feecode, String fixedfee, int msgformat,
			String validtime, String attime, String srctermid,
			String desttermid, String chargetermid, int msglength,
			String msgcontent, byte[] reserve, String productid, String Linkid) throws IOException{
		//��ȡ�����ļ�����
		Config config = new Config();
		
		//��ȡ���ò���
		String host = config.get("smgwip");
		String account = config.get("smgwaccount");
		String passwd = config.get("smgwpasswd");
		String spid = config.get("smgwspid");
		String spnum = config.get("smgpspnum");
		int port = Integer.parseInt(config.get("smgwport"));
		
		
		//��ʼ��client
		Client client = new Client(host, port, 2,account, passwd,spid, 0);
		
		//����submit
		Submit submit =new Submit();
		submit.setSrcTermid(spnum);
		submit.setDestTermid(desttermid);
		submit.setMsgContent(msgcontent.getBytes("iso-10646-ucs-2"));
		submit.setMsgFormat(msgformat);
		if (productid!=null) submit.setProductID(productid);
		
		// ���Ͷ���
		Result result = client.Send(submit);
		//�˳�
		client.Close();
		return result;
	}*/
	
	
	
}
